FROM {{ namespace }}/{{ image_prefix }}base:{{ tag }}
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"

{% block rabbitmq_header %}{% endblock %}

{% import "macros.j2" as macros with context %}

{{ macros.configure_user(name='rabbitmq') }}

{{ macros.enable_extra_repos(['rabbitmq']) }}

{% block rabbitmq_install %}
{% if base_package_type == 'rpm' %}
    {% set rabbitmq_packages = [
        'erlang-hipe',
        'hostname',
    ] %}
    {% if distro_package_manager == 'dnf' %}
        {% set rabbitmq_packages = rabbitmq_packages + [
            'rabbitmq-server-3.7.*'
        ] %}
    {% else %}
        # NOTE(mandre) Remove rabbitmq-server pinning once package dependencies are met
        # https://bugs.launchpad.net/kolla/+bug/1814233
        {% set rabbitmq_packages = rabbitmq_packages + [
            'rabbitmq-server-3.7.10'
        ] %}
    {% endif %}

{% elif base_package_type == 'deb' %}
    {% set rabbitmq_packages = [
        'erlang-nox',
        'logrotate',
        'rabbitmq-server',
    ] %}

    {% if base_arch == 'aarch64' %}
         {% set rabbitmq_packages = rabbitmq_packages + [
             'erlang-base',
         ] %}
    {% else %}
         {% set rabbitmq_packages = rabbitmq_packages + [
             'erlang-base-hipe',
         ] %}

    {% endif %}

{% endif %}

{{ macros.install_packages(rabbitmq_packages | customizable("packages")) }}

{% endblock %}

{% block rabbitmq_install_plugins %}

RUN rm -rf /var/lib/rabbitmq/* \
    && mkdir -p /usr/lib/rabbitmq/plugins \
    && /usr/lib/rabbitmq/bin/rabbitmq-plugins enable --offline \
       rabbitmq_management


    {% set rabbitmq_plugins = [
        'accept-0.3.3.ez',
        'prometheus-3.5.1.ez',
        'prometheus_cowboy-0.1.4.ez',
        'prometheus_httpd-2.1.8.ez',
        'prometheus_rabbitmq_exporter-3.7.2.4.ez'
    ] %}

{{ macros.install_rabbitmq_plugins(rabbitmq_plugins | customizable("plugins"), version="v3.7.2.4") }}
{% endblock %}

COPY extend_start.sh /usr/local/bin/kolla_extend_start
COPY rabbitmq_get_gospel_node.py /usr/local/bin/rabbitmq_get_gospel_node
RUN chmod 755 /usr/local/bin/kolla_extend_start /usr/local/bin/rabbitmq_get_gospel_node

{% block rabbitmq_footer %}{% endblock %}
{% block footer %}{% endblock %}

USER rabbitmq
